package com.ssn.composite.menu;

import java.util.ArrayList;
import java.util.List;

public class Menu {
    private String name;
    private List<Menu> subs;
    Menu(String name){
        this.name = name;
        if (subs == null){
            subs = new ArrayList<>();
        }
    }
    public void addSub(Menu menu){
        subs.add(menu);
    }
    public void removeSub(Menu menu){
        subs.remove(menu);
    }
    public void click(){
        System.out.println(name + "   clicked" + "show subs");
        for (Menu m: subs){
            System.out.println(m.name);
        }
    }
    public void showAllSubs(String prefix){
        System.out.println(prefix + this);
        prefix += " ";
        for (Menu m: subs) {
            m.showAllSubs(prefix);
        }
    }
    @Override
    public String toString() {
        return "Menu{" +
                "name='" + name + '\'' +
                '}';
    }
}
